import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { vipcardList } from '@apps/ant-bus/src/views/business/goods/vipcard/data/api';
import { isEmpty } from '@pkg/utils';
import { RenderType } from '@pkg/setting';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { DescItem } from '@apps/antd-admin/src/components/description';
import moment from 'moment';

export const columns: BasicColumn[] = [
  {
    title: '会员姓名',
    dataIndex: 'userName',
    width: 80,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 100,
  },
  {
    title: '退卡卡号',
    dataIndex: 'vipCardNo',
    width: 140,
  },
  {
    title: '退款日期',
    dataIndex: 'refundDate',
    width: 150,
  },
  {
    title: '支付价格',
    dataIndex: 'payAmount',
    width: 80,
  },
  {
    title: '退款金额',
    dataIndex: 'refundAmount',
    width: 100,
  },
  {
    title: '升降级卡种价格',
    dataIndex: 'upgradePayAmount',
    width: 120,
  },
  {
    title: '会员承担金额',
    dataIndex: 'vipBearAmount',
    width: 120,
  },
  {
    title: '销售承担金额',
    dataIndex: 'saleBearAmount',
    width: 120,
  },
  {
    title: '开卡日期',
    dataIndex: 'buyDate',
    width: 90,
  },
  {
    title: '所属地区',
    dataIndex: 'airportName',
    width: 140,
  },
  {
    title: '卡种名称',
    dataIndex: 'goodsName',
    width: 100,
  },
  {
    title: '所属销售',
    dataIndex: 'employeeName',
    width: 100,
  },
  {
    title: '退卡工单状态',
    dataIndex: 'isCheck',
    width: 150,
    dictData: [
      { label: '现办现退失败', value: -2 },
      { label: '现办现退中', value: -1 },
      { label: '现办现退成功', value: 0 },
      { label: '已提交', value: 1 },
      { label: '取消提交', value: 2 },
      { label: '退卡专员审核中', value: 3 },
      { label: '退卡专员取消退卡', value: 4 },
      { label: '退款专员审核中', value: 6 },
      { label: '退款专员取消退卡', value: 7 },
      { label: '退款专员驳回请求', value: 8 },
      { label: '退款专员已退款', value: 9 },
      { label: '退款专员已补退', value: 10 },
      { label: '退款专员已退卡未退款', value: 11 },
      { label: '退款专员退款中', value: 12 },
      { label: '退款专员退款失败', value: 13 },
      { label: '退款专员补退中', value: 14 },
      { label: '退款专员补退退款失败', value: 15 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '票务是否注销',
    dataIndex: 'ticketVipcardState',
    width: 150,
    dictData: [
      { label: '已注销', value: 1 },
      { label: '未注销', value: 2 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '支付Id',
    dataIndex: 'payInfoId',
    width: 250,
  },
  {
    title: '合卡销售',
    dataIndex: 'heKaRemark',
    width: 100,
  },
  {
    title: '退款银行',
    dataIndex: 'bank',
    width: 120,
  },
  {
    title: '退款卡号',
    dataIndex: 'bankNo',
    width: 120,
  },
  {
    title: '退款方式',
    dataIndex: 'refundWayDesc',
    width: 100,
  },
  {
    title: '退卡原因',
    dataIndex: 'refundReason',
    width: 250,
  },
  {
    title: '备注说明',
    dataIndex: 'remark',
    width: 250,
  },
  {
    title: '贵宾厅使用明细扣费说明',
    dataIndex: 'remarkc',
    width: 250,
  },
  {
    title: '电子金使用明细扣费说明',
    dataIndex: 'remarkd',
    width: 250,
  },
  {
    title: '补退方式',
    dataIndex: 'addRefundWay',
    width: 100,
    dictData: [{ label: '银行', value: 'refund_bank' }],
    renderType: RenderType.DICT,
  },
  {
    title: '补退金额',
    dataIndex: 'addRefundAmount',
    width: 120,
  },
  {
    title: '补退备注',
    dataIndex: 'addRefundRemark',
    width: 150,
  },
  {
    title: '标记备注',
    dataIndex: 'tagRemark',
    width: 150,
  },
  {
    title: '提交人',
    dataIndex: 'submitUserName',
    width: 100,
  },
  {
    title: '申请日期',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mainAccount',
    label: '会员账号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'userName',
    label: '会员姓名',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'employeeName',
    label: '销售姓名',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'employeeAccount',
    label: '销售账号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'startDate',
    label: '申请开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '申请结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'airportIdArray',
    label: '机场',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      params: { handlerName: 'busAirportRoleListHandler' },
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
      mode: 'multiple',
    },
  },
  {
    field: 'goodsIdArray',
    label: '卡种',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
      mode: 'multiple',
    },
  },
  {
    field: 'isCheck',
    label: '审核状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '现办现退失败', value: -2 },
          { label: '现办现退中', value: -1 },
          { label: '现办现退成功', value: 0 },
          { label: '已提交', value: 1 },
          { label: '取消提交', value: 2 },
          { label: '退卡专员审核中', value: 3 },
          { label: '退卡专员取消退卡', value: 4 },
          { label: '退款专员审核中', value: 6 },
          { label: '退款专员取消退卡', value: 7 },
          { label: '退款专员驳回请求', value: 8 },
          { label: '退款专员已退款', value: 9 },
          { label: '退款专员已补退', value: 10 },
          { label: '退款专员已退卡未退款', value: 11 },
          { label: '退款专员退款中', value: 12 },
          { label: '退款专员退款失败', value: 13 },
          { label: '退款专员补退中', value: 14 },
          { label: '退款专员补退退款失败', value: 15 },
        ],
        showSearch: true,
        filterOption: (input: string, option: any) => {
          return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
      };
    },
  },
  {
    field: 'refundStartDate',
    label: '退款开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'refundEndDate',
    label: '退款结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'exportTimeType',
    label: '导出时间选择',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '按申请日期导出', value: 1 },
        { label: '按退款日期导出', value: 2 },
      ],
    },
  },
];

export const commonInfoSchema: DescItem[] = [
  {
    field: 'userName',
    label: '会员姓名',
    span: 3,
  },
  {
    field: 'mobile',
    label: '手机号',
    span: 3,
  },
  {
    field: 'vipCardNo',
    label: '退卡卡号',
    span: 3,
  },
  {
    field: 'buyDate',
    label: '开卡日期',
    span: 3,
  },
  {
    field: 'payAmount',
    label: '支付金额',
    span: 3,
  },
  {
    field: 'payWayName',
    label: '支付方式',
    span: 3,
  },
  {
    field: 'goodsName',
    label: '卡种名称',
    span: 3,
  },
  {
    field: 'openAirportName',
    label: '开卡地区',
    span: 3,
  },
  {
    field: 'isUpgrade',
    label: '升降级过卡种',
    span: 3,
    render: (curVal, data) => {
      let isUpgradeArray = [
        { label: '升降级过', value: 1 },
        { label: '没有升降级', value: 0 },
      ];
      const isUpgrade: any = isUpgradeArray.find(item => item.value == curVal);
      if (isUpgrade) {
        return render.renderTag(isUpgrade.label, 'red');
      }
      return '';
    },
  },
  {
    field: 'upgradePayAmount',
    label: '升级卡金额',
    span: 3,
    show: (data: any) => {
      return data.isUpgrade == 1;
    },
  },
  {
    field: 'realRefundAmount',
    label: '已退金额',
    span: 3,
  },
  {
    field: 'canRefundOriginal',
    label: '原路退还',
    span: 3,
    render: (curVal, data) => {
      console.log('canRefundOriginal:', curVal);
      let canRefundOriginalArray = [
        { label: '支持', value: 1 },
        { label: '不支持', value: 2 },
      ];
      const canRefundOriginal: any = canRefundOriginalArray.find(item => item.value == curVal);
      if (canRefundOriginal) {
        return render.renderTag(canRefundOriginal.label, 'red');
      }
      return '';
    },
  },
];
/**
 * -2现办现退失败，-1现办现退中，0现办现退成功，1已提交,2取消提交,3退卡专员审核中,4退卡专员取消退卡,6退款专员审核中,7退款专员取消退卡,
 * 8退款专员驳回请求,9退款专员已退款,10退款专员已补退,11退款专员已退卡未退款,12退卡专员退款中,13退卡专员已退款
 * 补充内容表单 isCheck == 6 退款专员审核中状态可以补充信息
 */
export const formSchema6: FormSchema[] = [
  {
    label: '主键',
    field: 'backcardRecordId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '审核状态',
    field: 'isCheck',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '支付金额',
    field: 'payAmount',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '是否支持原路退款',
    field: 'canRefundOriginal',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '是否升降级',
    field: 'isUpgrade',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '承担方式',
    field: 'bearWay',
    component: 'RadioGroup',
    required: true,
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      let isUpgrade = formModel.isUpgrade;
      console.info(isUpgrade);
      return {
        options: [
          { label: '会员同意全部承担', value: 1 },
          { label: '会员不同意全部承担', value: 2 },
        ],
        onChange: data => {
          console.info('bearWay', data.target.value);
          if (data.target.value == 1) {
            console.info('bearWay', 2);
            formModel.saleBearAmount = 0;
          }
        },
      };
    },
  },
  {
    label: '会员承担金额提示',
    field: 'vipBearAmountTip',
    slot: 'vipBearAmountTip',
    component: 'Input',
  },
  {
    label: '会员承担金额',
    field: 'vipBearAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let payAmount = formModel.payAmount;
      return {
        min: 0,
        max: payAmount,
        onChange: value => {
          console.info(payAmount);
          formModel.refundAmount = Number((Number(payAmount) - Number(value)).toFixed(2));
        },
      };
    },
  },
  {
    label: '销售承担金额',
    field: 'saleBearAmount',
    component: 'InputNumber',
    required: true,
    show: ({ model }) => {
      if (model.bearWay == 2) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '线上原路退回提示',
    field: 'refundWayTip',
    slot: 'refundWayTip',
    component: 'Input',
  },
  {
    label: '退款方式',
    field: 'refundWay',
    required: true,
    component: 'RadioGroup',
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '原路退回', value: 'refund_original', disabled: formModel.canRefundOriginal != 1 },
          { label: '银行卡', value: 'refund_bank' },
        ],
      };
    },
  },
  {
    label: '开户银行',
    field: 'bank',
    component: 'Input',
    required: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
    ifShow: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '银行卡号',
    field: 'bankNo',
    component: 'Input',
    required: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
    ifShow: ({ model, values }) => {
      if (values.refundWay == 'refund_bank') {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '退款金额',
    field: 'refundAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let isUpgrade = formModel.isUpgrade;
      console.info(isUpgrade);
      return {
        disabled: isUpgrade == 0,
        max: formModel.payAmount,
      };
    },
  },
  {
    label: '申请退卡备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '退卡专员备注',
    field: 'remarka',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '贵宾厅使用明细扣费说明',
    field: 'remarkc',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '电子金使用明细扣费说明',
    field: 'remarkd',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '退卡原因',
    field: 'refundReason',
    component: 'InputTextArea',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '垫付凭据',
    field: 'dianTuiImg',
    component: 'ImageUpload',
    required: false,
    componentProps: {
      disabled: true,
    },
  },
  {
    label: '驳回原因',
    field: 'remarkb',
    component: 'InputTextArea',
    dynamicDisabled: true,
    required: false,
    ifShow: ({ model }) => {
      if (!isEmpty(model.remarkb)) {
        return true;
      } else {
        return false;
      }
    },
  },
];

export const formSchema8: FormSchema[] = [
  {
    label: '主键',
    field: 'backcardRecordId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '审核状态',
    field: 'isCheck',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '驳回原因',
    field: 'remarkb',
    component: 'InputTextArea',
    required: true,
  },
];

export const formSchema9: FormSchema[] = [
  {
    label: '主键',
    field: 'backcardRecordId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '审核状态',
    field: 'isCheck',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '是否支持原路退款',
    field: 'canRefundOriginal',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '支付方式',
    field: 'payType',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '垫付凭据',
    field: 'dianTuiImg',
    component: 'ImageUpload',
    required: false,
  },
  {
    label: '线上原路退回提示',
    field: 'refundWayTip',
    slot: 'refundWayTip',
    component: 'Input',
  },
  {
    label: '退款方式',
    field: 'refundWay',
    component: 'Select',
    required: true,
    defaultValue: 'refund_bank',
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '原路退回', value: 'refund_original', disabled: formModel.canRefundOriginal != 1 },
          { label: '银行', value: 'refund_bank' },
        ],
      };
    },
  },
  {
    label: '承担方式',
    field: 'bearWay',
    component: 'RadioGroup',
    dynamicDisabled: true,
    componentProps: {
      options: [
        { label: '会员同意全部承担', value: 1 },
        { label: '会员不同意全部承担', value: 2 },
      ],
    },
  },
  {
    label: '会员承担金额',
    field: 'vipBearAmount',
    component: 'InputNumber',
    dynamicDisabled: true,
  },
  {
    label: '销售承担金额',
    field: 'saleBearAmount',
    component: 'InputNumber',
    dynamicDisabled: true,
  },
  {
    label: '退款金额',
    field: 'refundAmount',
    component: 'InputNumber',
    required: true,
    dynamicDisabled: true,
    componentProps: ({ formModel }) => {
      let payAmount = formModel.payAmount;
      return {
        min: 0,
        max: payAmount,
      };
    },
  },
  {
    label: '退款时间',
    field: 'refundDate',
    component: 'DatePicker',
    required: false,
    ifShow: ({ model }) => {
      if (model.isCheck == 9) {
        return true;
      } else {
        return false;
      }
    },
    componentProps: {
      placeholder: '非必填，当时忘审核的话选择退款日期',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
      disabledDate: current => {
        return current && current >= moment().add(0, 'day');
      },
    },
  },
  {
    label: '备注',
    field: 'remarkb',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '退款凭证',
    field: 'refundImg',
    component: 'ImageUpload',
  },
];

export const formSchema10: FormSchema[] = [
  {
    label: '主键',
    field: 'backcardRecordId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '审核状态',
    field: 'isCheck',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '是否可原路退回',
    field: 'canRefundOriginal',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '最大补退金额',
    field: 'maxAddRefundAmount',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '补退退款方式',
    field: 'addRefundWay',
    component: 'Select',
    required: true,
    defaultValue: 'refund_bank',
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '原路退回', value: 'refund_original', disabled: formModel.canRefundOriginal != 1 },
          { label: '银行', value: 'refund_bank' },
        ],
      };
    },
  },
  {
    label: '补退金额',
    field: 'addRefundAmount',
    component: 'InputNumber',
    required: true,
    componentProps: ({ formModel }) => {
      let maxAddRefundAmount = formModel.maxAddRefundAmount;
      return {
        min: 0,
        max: maxAddRefundAmount,
      };
    },
  },
  {
    label: '补退备注',
    field: 'addRefundRemark',
    component: 'InputTextArea',
    required: true,
  },
];

export const formSchema11: FormSchema[] = [
  {
    label: '主键',
    field: 'backcardRecordId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '审核状态',
    field: 'isCheck',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '未退款备注',
    field: 'tagRemark',
    component: 'InputTextArea',
    required: true,
  },
];

export const formSchemaRefundDate: FormSchema[] = [
  {
    label: '主键',
    field: 'backcardRecordId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '会员卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '退款时间',
    field: 'refundDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      placeholder: '非必填，当时忘审核的话选择退款日期',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
      disabledDate: current => {
        return current && current >= moment().add(0, 'day');
      },
    },
  },
];
